home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / tek / tekrgmac.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-07  |  11.8 KB  |  680 lines

  1. #ifdef lint
  2. static char *SCCSid = "%W%    (NCSA)    %G%";
  3. #endif
  4.  
  5. /*
  6.  
  7. rgmac.c by Gaige B. Paulsen
  8.   spawned from rgp.c by Aaron Contorer for NCSA
  9. Copyright 1987, board of trustees, University of Illinois
  10.  
  11. Routines for Macintosh Window output.  
  12.  
  13. */
  14.  
  15.  
  16. /* 
  17.  *    Include files 
  18.  */
  19.  
  20. #include <stdio.h>
  21. #include <String.h>
  22.  
  23. #include <Controls.h>
  24. #include <Dialogs.h>
  25. #include <Events.h>
  26. #include <OSutils.h>
  27. #include <Packages.h>
  28. #include <Quickdraw.h>
  29. #include <Windows.h>
  30. #include <Memory.h>
  31.  
  32. #ifdef MPW
  33. #include "mpw.h"
  34. #endif MPW
  35. #include "configrec.h"
  36. #include "maclook.h"
  37. #include "whatami.h"
  38. #include "vgtek.h"
  39. #include "tools.h"
  40. #include "util.h"
  41. #include "rsmac.h"
  42.  
  43. #define TRUE 1
  44. #define FALSE 0
  45.  
  46. #define SPLASH_SQUARED    4
  47.  
  48. /*
  49.  * display structure....
  50.  */
  51.  
  52. struct RGMwindows {
  53. GrafPtr
  54.     wind;
  55. int
  56.     xorigin,
  57.     yorigin,
  58.     xscale,
  59.     yscale,
  60.     vg,
  61.     vs,
  62.     inuse,
  63.     ingin;
  64. unsigned char
  65.     *name;
  66. int
  67.     width,
  68.     height;
  69. ControlHandle
  70.     zoom,
  71.     vert,
  72.     horiz;
  73.     } *RGMwind[ MAXWIND ];    /* BYU - changed from an array of structure to an array of pointers */
  74.  
  75. long RGMlastclick;
  76.  
  77. int RGMcolor[]=
  78.     { 30,            /* black */
  79.       33,            /* white */
  80.       205,            /* red */
  81.       341,            /* green */
  82.       409,            /* blue */
  83.       273,            /* cyan */
  84.       137,            /* magenta */
  85.       69            /* yellow */
  86.       };
  87.  
  88.  
  89. char *macname = "Macintosh Windows";
  90.  
  91. int RGsetwind
  92.   (
  93.     int dnum
  94.   )
  95. {
  96.  
  97.     if (dnum<0 || dnum>=MAXWIND) return(-1);
  98.  
  99.     if (!RGMwind[dnum]->inuse) return(-1);
  100.  
  101.     SetPort( RGMwind[dnum]->wind);
  102.     return(0);
  103. }
  104.  
  105. RGMgin(w)
  106. {
  107.     if (RGsetwind(w)) return(-1);
  108.  
  109.     setgraphcurs();
  110.     RGMwind[w]->ingin=1;
  111. }
  112.  
  113. RGMoutfunc(f)
  114.     int (*f)();
  115.   {
  116. #pragma unused(f)
  117.   }
  118.  
  119.  
  120. RGMpencolor(w, color)
  121. {
  122.     if (RGsetwind(w) ) return(-1);
  123.  
  124.     ForeColor((long) RGMcolor[color] );
  125. }
  126.  
  127. RGMclrscr(w)
  128. {
  129.     if (RGsetwind(w) ) return(-1);
  130.  
  131.     PaintRect(&RGMwind[w]->wind->portRect);
  132. }
  133.  
  134. RGMclose(w)
  135. {
  136.     if (RGsetwind(w) ) return(-1);
  137.  
  138.     DisposeWindow(RGMwind[w]->wind);
  139.     RGMwind[w]->inuse  = FALSE;
  140.  
  141. }
  142.  
  143. RGMpoint(w,x,y)
  144. {
  145.     if (RGsetwind(w) ) return(-1);
  146.  
  147.     MoveTo(x,y);
  148.     LineTo(x,y);
  149.  
  150. RGMdrawline(w,x0,y0,x1,y1)
  151. int w,x0,y0,x1,y1;
  152. {
  153.     if (RGsetwind(w) ) return(-1);
  154.  
  155.     x0 = (int) ((long) x0 * RGMwind[w]->width / INXMAX);
  156.     y0 = RGMwind[w]->height - (int) ((long) y0 * RGMwind[w]->height / INYMAX);
  157.     x1 = (int) ((long) x1 * RGMwind[w]->width/INXMAX);
  158.     y1 = RGMwind[w]->height - (int) ((long) y1 * RGMwind[w]->height / INYMAX);
  159.  
  160.     MoveTo(x0,y0);
  161.     LineTo(x1,y1);
  162. }
  163.  
  164. RGMpagedone(w)
  165.   {
  166. #pragma unused(w)
  167.   }
  168.  
  169. RGMdataline(w,data,count)
  170.   {
  171. #pragma unused(w, data, count)
  172.   }
  173.  
  174.  
  175. RGMcharmode(w,rotation,size)
  176.   {
  177. #pragma unused(w, rotation, size)
  178.   }
  179.  
  180. RGMshowcur()
  181.   {
  182.   }
  183.  
  184. RGMlockcur()
  185.   {
  186.   }
  187.  
  188. RGMhidecur()
  189.   {
  190.   }
  191.  
  192. RGMbell(w)
  193.   {
  194. #pragma unused(w)
  195.   }
  196.  
  197. RGMuncover(w)
  198.   {
  199. #pragma unused(w)
  200.   }
  201.  
  202. char *RGMdevname() {
  203.     return(macname);
  204. }
  205.  
  206. int RGMalloc()            /* BYU - allocate this structure to save global space */
  207. {                    /* BYU */
  208.     int i;                            /* BYU */
  209.     for(i=0; i<MAXWIND; i++) {        /* BYU */
  210.         RGMwind[i] = (struct RGMwindows *) NewPtr((long) sizeof(struct RGMwindows));    /* BYU */
  211.         if (RGMwind[i]) {                        /* BYU */
  212.             RGMwind[i]->wind = (GrafPtr) 0;        /* BYU */
  213.             RGMwind[i]->vg = -1;                /* BYU - necessary */
  214.             RGMwind[i]->vs = -1;                /* BYU */
  215.             RGMwind[i]->inuse = 0;                /* BYU - necessary */
  216.         } else                                     /* BYU */
  217.             return -1;                /* BYU - insufficient memory */
  218.     }                        /* BYU */
  219.     return(0);        /* BYU */
  220. }                    /* BYU */
  221.  
  222. RGMinit()
  223. {
  224.     int i;
  225.     for (i = 0; i < MAXWIND; i++)
  226.         RGMwind[i]->inuse = 0;
  227. }
  228.  
  229. RGMinfo(w,v,a,b,c,d)
  230.     int w,a,b,c,d,v;
  231.   {
  232. #pragma unused(a, b, c, d)
  233.     RGMwind[w]->vg=v;
  234.   }
  235.  
  236. RGMgmode()
  237. {}
  238.  
  239. RGMtmode()
  240. {}
  241.  
  242. RGMnewwin()
  243. {
  244. int i = 0;
  245. int maxdim =0;
  246.  
  247.     while ((i < MAXWIND) && (RGMwind[i]->inuse)) i++;
  248.  
  249.     if (i >= MAXWIND) return(-1);
  250.  
  251.     RGMwind[i]->wind = GetNewWindow(256, (Ptr) 0L, (WindowPtr) -1L);
  252.  
  253.     if (RGMwind[i]->wind == 0L) return(-1);
  254.     if (qd.screenBits.bounds.bottom > 400)
  255.         {
  256.         SizeWindow(RGMwind[i]->wind, 400, 300, FALSE);
  257.         maxdim = 400;
  258.         }
  259.     else
  260.         maxdim = 342;
  261.  
  262.     RGMwind[i]->vg = -1;                /* BYU */
  263.     RGMwind[i]->vs = -1;                /* BYU */
  264.     RGMwind[i]->xorigin = 0;
  265.     RGMwind[i]->yorigin = 0;
  266.     RGMwind[i]->xscale  = WINXMAX;        /* BYU 2.4.7 - added the "W" */
  267.     RGMwind[i]->yscale  = WINYMAX;        /* BYU 2.4.7 - added the "W" */
  268.     RGMwind[i]->width   = maxdim;            /* BYU 2.4.7 - was 256 */
  269.     RGMwind[i]->height  = (maxdim*3)/4;            /* BYU 2.4.7 - was 342 */
  270.     RGMwind[i]->inuse   = TRUE;
  271.     RGMwind[i]->ingin   = 0;
  272.  
  273.     ValidRect(&RGMwind[i]->wind->portRect);
  274.  
  275.     return(i);
  276. }
  277.  
  278. int RGfindbyVG
  279.   (
  280.     int vg
  281.   )
  282. {
  283. int i = 0;
  284.  
  285.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->vg != vg)))
  286.         i++;
  287.     if (i >= MAXWIND) return(-1);
  288.     return(i);
  289. }
  290.  
  291. int RGattach
  292.   (
  293.     int vg,
  294.     int virt,
  295.     char *name
  296.   )
  297. {
  298. int        dnum;
  299. long    time;
  300. char    myname[256],ts[256];
  301.  
  302.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);
  303.  
  304. sprintf(ts,"RGattach: vg = %d, vs = %d, \042%s\042);  dnum = %d",    /* BYU */
  305.     vg,virt,name,dnum);                                                /* BYU */
  306. putln(ts);
  307.  
  308.     RGMwind[dnum]->vs = virt;
  309.     RGMwind[dnum]->name = (char *) NewPtr((long) 256);    /* BYU */
  310.  
  311.     if (RGMwind[dnum]->name == 0L) return(-2);
  312.  
  313. #if 1                                    /* BYU */
  314.     myname[0] = 165;                    /* BYU - the "dot" */
  315.     strncpy(&myname[1],name,254);        /* BYU - don't copy too much */
  316. #else                                    /* BYU */
  317.     RGMwind[dnum]->name[0] = 165;
  318.     strncpy(&RGMwind[dnum]->name[1],name,255);
  319. #endif                                    /* BYU */
  320.  
  321.     GetDateTime((unsigned long *) &time);
  322.     iutimestring(time,FALSE,ts);                    /* Put time in the temp string */
  323.  
  324. #if 1                                    /* BYU */
  325.     strncat(myname,"  ",4);                /* BYU - Space, please */
  326.     strncat(myname,ts,64);                /* BYU - Place the time string at the end */
  327.     strcpy(RGMwind[dnum]->name,myname);    /* BYU */
  328. #else                                    /* BYU */
  329.     strncat(RGMwind[dnum]->name,"  ",255);            /* Space, please */
  330.     strncat(RGMwind[dnum]->name,ts,255);            /* Place the time string at the end */
  331. #endif
  332.  
  333. #if 1                                            /* BYU */
  334.     if (RGMwind[dnum]->wind != (GrafPtr) 0)     /* BYU */
  335.         setwtitle(RGMwind[dnum]->wind,myname);    /* BYU */
  336. #else                                            /* BYU */
  337.     setwtitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);
  338. #endif                                            /* BYU */
  339.     return(0);
  340. }
  341.  
  342.  
  343. int RGdetach        /* BYU */
  344.   (
  345.     int vg            /* BYU */
  346.   )
  347. {
  348. int dnum;            /* BYU */
  349. char    temp[64];
  350.  
  351.     if ((dnum = RGfindbyVG(vg)) < 0) return(-1);        /* BYU */
  352.     if (dnum >= MAXWIND)  return(-1);                    /* BYU */
  353.  
  354. sprintf(temp,"RGdetach: dnum = %d, vg = %d, vs = %d, Wind = %lx",    /* BYU */
  355.     dnum,RGMwind[dnum]->vg,RGMwind[dnum]->vs,RGMwind[dnum]->wind);    /* BYU */
  356. putln(temp);
  357.     if (RGMwind[dnum]->vs != -1) {                 /* BYU */
  358.         if (RGMwind[dnum]->wind != (GrafPtr) 0) {    /* BYU */
  359.             strncpy(RGMwind[dnum]->name,&RGMwind[dnum]->name[1],255);    /* BYU */
  360.             setwtitle(RGMwind[dnum]->wind,RGMwind[dnum]->name);            /* BYU */
  361.         }                            /* BYU */
  362.     }                                /* BYU */
  363.     return(0);                        /* BYU */
  364. }
  365.  
  366. int RGfindbywind
  367.   (
  368.     GrafPtr wind
  369.   )
  370. {
  371. int i = 0;
  372.  
  373.     while ((i < MAXWIND) && ((!RGMwind[i]->inuse) || (RGMwind[i]->wind != wind)))
  374.         i++;
  375.     if (i >= MAXWIND) return(-1);
  376.     return(i);
  377. }
  378.  
  379. int RGupdate
  380.   (
  381.     GrafPtr wind
  382.   )
  383. {
  384. int    i = 0,done;
  385.  
  386.     if ((i = RGfindbywind(wind)) < 0)
  387.         return(-1);
  388.  
  389.     SetPort(wind);
  390.     BeginUpdate(wind);
  391.  
  392.     VGstopred(RGMwind[i]->vg);
  393.     VGpage(RGMwind[i]->vg);
  394.     done = VGpred(RGMwind[i]->vg,RGMwind[i]->vg);
  395.     EndUpdate(wind);
  396.     if (!done)
  397.         netputevent(1,128,RGMwind[i]->vg);
  398.     return(done);
  399. }
  400.  
  401. int RGsupdate
  402.   (
  403.     int i
  404.   )
  405. {
  406. int rg;
  407.  
  408.     rg = RGfindbyVG(i);
  409.  
  410.     if (rg < 0) return(0);
  411.     SetPort(RGMwind[rg]->wind);
  412.     if (!VGpred(RGMwind[rg]->vg,RGMwind[rg]->vg))
  413.     {
  414.         netputevent(1,128,i);
  415.     }
  416.     else
  417.         return(1);
  418.     return(0);
  419. }
  420.  
  421. int RGgetVG
  422.   (
  423.     GrafPtr wind
  424.   )
  425. {
  426. int i;
  427.  
  428.     i = RGfindbywind(wind);
  429.  
  430.     return(RGMwind[i]->vg);
  431. }
  432.  
  433. int RGgetdnum
  434.   (
  435.     GrafPtr wind
  436.   )
  437. {
  438.     return(RGfindbywind(wind));
  439. }
  440.  
  441. int RGgetVS
  442.   (
  443.     int dnum
  444.   )
  445. {
  446.     return(RGMwind[dnum]->vs);
  447. }
  448.  
  449. inSplash(p1, p2)
  450. Point *p1,*p2;
  451. {
  452.     if ((p1->h - p2->h > 3) || (p2->h - p1->h > 3))
  453.         return(0);
  454.     if ((p1->v - p2->v > 3) || (p2->v - p1->v > 3))
  455.         return(0);
  456.  
  457.     return(1);
  458. }
  459.  
  460. long *Ticks = (long *) 0x16a;
  461.  
  462. void VidSync
  463.   (
  464.     void
  465.   )
  466. {
  467. long    a;
  468.  
  469.     a = *Ticks;
  470.     while (a == *Ticks);
  471. }
  472.  
  473. /*
  474.     Resize the tek window. It will always be sqare.
  475. */
  476.  
  477. void RGsize (GrafPtr wind, Point * where)
  478. {
  479.     union {
  480.         Point pt;
  481.         long lg;
  482.     } size;
  483.     Rect SizRect;
  484.     int i;
  485.     
  486.     if ((i = RGfindbywind(wind)) < 0)
  487.         return;
  488.         
  489.     SetRect(&SizRect, 48, 48, 2000,2000);
  490.     
  491.     if (where)
  492.       {                            /* grow icon actions */
  493.         size.lg = growwindow(wind, (Point *) where, &SizRect);
  494.         if ((long) size.lg != 0L)
  495.             {
  496.             if (size.pt.h > size.pt.v)
  497.                 size.pt.h = size.pt.v;
  498.             else
  499.                 size.pt.v = size.pt.h;
  500.                 
  501.             if ((long) size.lg)
  502.                 {
  503.                 SizeWindow(wind, size.pt.h, size.pt.v, FALSE);
  504.                 RGMwind[i]->width   = size.pt.h;             
  505.                 RGMwind[i]->height  = size.pt.h;
  506.                 SetPort (wind);
  507.                 InvalRect(&wind->portRect);    /* Don't forget to redraw */ 
  508.                 }
  509.             }
  510.         else
  511.             return;                            /* user skipped growing */
  512.       }
  513.  
  514. }
  515.  
  516. void RGmousedown
  517.   (
  518.     GrafPtr wind,
  519.     Point *wherein
  520.   )
  521. {
  522. long    lx,ly;
  523. char    thispaceforent[6];
  524. int        i;
  525. Point    where;
  526. char    dum[32];
  527.  
  528.     where = *wherein;
  529.     if ((i = RGfindbywind(wind)) < 0)
  530.         return;
  531.  
  532.     if (!RGMwind[i]->ingin)
  533.     {
  534.     Point    anchor,current,last;
  535. #ifndef MPW
  536.     long    TickCount();
  537. #endif MPW
  538.     long    tc;
  539.     int        x0,y0,x1,y1;
  540.     Rect    rect;
  541.     
  542.         SetPort(wind);
  543.     
  544.         last  = where;
  545.         current = where;
  546.         anchor = where;
  547.     
  548.         PenPat((ConstPatternParam)qd.gray);    
  549.         PenMode(patXor);
  550.     
  551.         SetRect(&rect,0,0,0,0);
  552.     
  553.         while (StillDown())
  554.         {
  555.             GetMouse(¤t);
  556.             if (inSplash(¤t,&anchor)) continue;
  557.             
  558.             if ((current.h - anchor.h)*4 < 3*(current.v - anchor.v))    /* tlr */
  559.                 current.h = (anchor.h + (current.v - anchor.v))*4/3;
  560.             else
  561.                 current.v = (anchor.v + (current.h - anchor.h))*3/4;
  562.                 
  563.             tc = TickCount();
  564.             while(TickCount() == tc);
  565.             VidSync();
  566.             FrameRect(&rect);
  567.     
  568.             if (anchor.v < current.v)
  569.             {
  570.                 rect.top = anchor.v;
  571.                 rect.bottom = current.v;
  572.             }
  573.             else
  574.             {
  575.                 rect.top = current.v;
  576.                 rect.bottom = anchor.v;
  577.             }
  578.     
  579.             if (anchor.h < current.h)
  580.             {
  581.                 rect.left = anchor.h;
  582.                 rect.right = current.h;
  583.             }
  584.             else
  585.             {
  586.                 rect.right = anchor.h;
  587.                 rect.left = current.h;
  588.             }
  589.             
  590.             FrameRect(&rect);
  591.             last = current;
  592.         }
  593.     
  594.         FrameRect(&rect);
  595.  
  596.         PenPat(qd.black);    
  597.         PenMode(patCopy);
  598.  
  599.         if (!inSplash(&anchor,¤t))
  600.         {
  601.             x0 = (int) ((long) rect.left * RGMwind[i]->xscale / RGMwind[i]->width );
  602.             y0 = (int) (RGMwind[i]->yscale -
  603.                     (long) rect.top * RGMwind[i]->yscale / RGMwind[i]->height);
  604.             x1 = (int) ((long) rect.right * RGMwind[i]->xscale / RGMwind[i]->width);
  605.             y1 = (int) (RGMwind[i]->yscale -
  606.                     (long) rect.bottom * RGMwind[i]->yscale / RGMwind[i]->height);
  607.             x1 = (x1 < x0+2) ? x0 + 4 : x1;
  608.             y0 = (y0 < y1+2) ? y1 + 4 : y0;
  609.  
  610.             VGzoom( i,
  611.                     x0 + RGMwind[i]->xorigin,
  612.                     y1 + RGMwind[i]->yorigin,
  613.                     x1 + RGMwind[i]->xorigin,
  614.                     y0 + RGMwind[i]->yorigin);
  615.  
  616.             VGpage(RGMwind[i]->vg);
  617.  
  618.             RGMwind[i]->xscale  = x1 - x0;
  619.             RGMwind[i]->yscale  = y0 - y1;
  620.             RGMwind[i]->xorigin = x0 + RGMwind[i]->xorigin;
  621.             RGMwind[i]->yorigin = y1 + RGMwind[i]->yorigin;
  622.  
  623.             while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  624.                 Stask();
  625.             RGMlastclick = 0L;
  626.         }
  627.         else
  628.         {
  629.             if (RGMlastclick && ((RGMlastclick + GetDblTime()) > TickCount()))
  630.             {
  631.                 RGMwind[i]->xscale  = WINXMAX;    /* BYU 2.4.7 - added the "W" */
  632.                 RGMwind[i]->yscale  = WINYMAX;    /* BYU 2.4.7 - added the "W" */
  633.                 RGMwind[i]->xorigin = 0;
  634.                 RGMwind[i]->yorigin = 0;
  635.  
  636.                 VGzoom(i,0,0,WINXMAX-1,WINYMAX-1);    /* BYU 2.4.7 - added the "W" */
  637.                 VGpage( RGMwind[i]->vg);
  638.                 while(!VGpred(RGMwind[i]->vg,RGMwind[i]->vg))
  639.                     Stask();
  640.                 RGMlastclick = 0L;
  641.             }
  642.             else RGMlastclick = TickCount();
  643.         }
  644.         return;
  645.     
  646.     }
  647.  
  648.     lx = (RGMwind[i]->xscale * where.h) / ((long) RGMwind[i]->width);
  649.     ly = RGMwind[i]->yscale -
  650.         ((RGMwind[i]->yscale * where.v) / ((long) RGMwind[i]->height));
  651.  
  652.     VGgindata(RGMwind[i]->vg,(int) lx,(int) ly,' ',thispaceforent);
  653.  
  654. sprintf(dum,"GIN i: %d, vs: %d\n",i,RGMwind[i]->vs);
  655. putln(dum);
  656.  
  657.     RSsendstring(RGMwind[i]->vs,thispaceforent,5);
  658.     sprintf(dum," \r\n");
  659.     RSsendstring(RGMwind[i]->vs,dum,3);
  660.     
  661.  
  662.     /*    RGMwind[i]->ingin = 0; */
  663.     unsetgraphcurs();
  664.     RGMlastclick = TickCount();
  665. }
  666.  
  667. void RGMgetrect
  668.   (
  669.       int src,
  670.     Rect * inRect
  671.   )
  672. {
  673.     inRect->top = 0;
  674.     inRect->left = 0;
  675.     inRect->bottom = RGMwind[src]->height;
  676.     inRect->right = RGMwind[src]->width;
  677.     return;
  678. }
  679.